function newWindow(x1, y1, x2, y2, titre, texte, couleur1, couleur2, couleur3, couleur4)
   Window = { }
   Window.x = x1
   Window.y = y1
   Window.xmax = x2
   Window.ymax = y2
   Window.titre = titre
   Window.texte = texte
   Window.move = 0
   Window.resize = 0
   Window.col1 = couleur1
   Window.col2 = couleur2
   Window.col3 = couleur3
   Window.col4 = couleur4
   return Window
end

function Stylus.heldinWindow(Window, a, b)
   if Stylus.held and a > Window.x and a < Window.x+Window.xmax and b > Window.y and b < Window.y+9 then
      Window.move = 1
   end
   if Stylus.held and Window.move == 1 then
      Window.x = a-(Window.xmax/2)
      Window.y = b-3
   end
   if Stylus.released then
      Window.move = 0
      Window.resize = 0
   end
   if Stylus.held and a > Window.x+Window.xmax-5 and a < Window.x+Window.xmax+5 and b > Window.y+Window.ymax-5 and b < Window.y+Window.ymax+5 then
      Window.resize = 1
   end
   if Window.resize == 1 and Stylus.held then
      Window.xmax = a-Window.x
      Window.ymax = b-Window.y
   end
   if Window.x < 0 then Window.x = 0 end
   if Window.y < 0 then Window.y = 0 end
   if Window.x+10 > 246 then Window.x = 246 end
   if Window.y+9 > 192 then Window.y = 192-9 end
   if Window.xmax<60 then Window.xmax = 60 end
   if Window.ymax<40 then Window.ymax = 40 end
   return Window
end

function drawWindow(Window)
   screen.drawGradientRect(SCREEN_DOWN, Window.x, Window.y, Window.x+Window.xmax, Window.y+9, Window.col1, Window.col1, Window.col1, Window.col4)
   screen.drawGradientRect(SCREEN_DOWN, Window.x, Window.y+9, Window.x+Window.xmax, Window.y+Window.ymax, Window.col3, Window.col3, Window.col3, Window.col3)
   screen.drawRect (SCREEN_DOWN, Window.x, Window.y, Window.x+Window.xmax, Window.y+Window.ymax, Window.col2)
   screen.drawLine (SCREEN_DOWN, Window.x, Window.y+9, Window.x+Window.xmax, Window.y+9, Window.col2)
   screen.drawLine (SCREEN_DOWN, Window.x+Window.xmax-6, Window.y+Window.ymax-3, Window.x+Window.xmax-2, Window.y+Window.ymax-3, Window.col2)
   screen.drawLine (SCREEN_DOWN, Window.x+Window.xmax-3, Window.y+Window.ymax-6, Window.x+Window.xmax-3, Window.y+Window.ymax-2, Window.col2)
   screen.drawTextBox (SCREEN_DOWN, Window.x+1, Window.y+11, Window.x+Window.xmax-1, Window.y+Window.ymax-1, Window.texte, Window.col2)
   screen.drawTextBox (SCREEN_DOWN, Window.x+1, Window.y+1, Window.x+Window.xmax-1, Window.y+9, Window.titre, Window.col2)
   return Window
end
